package com.zxs.aspect;

import com.zxs.service.DingTalkService;
import jakarta.annotation.Resource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class DingTalkAspect {

    @Autowired(required = false)
    private DingTalkService dingTalkService;

    @Pointcut("@annotation(com.zxs.annotation.DingTalkFix)")
    public void dingTalkPointcut() {
    }

    @Pointcut("@annotation(com.zxs.annotation.DingTalkBack)")
    public void dingTalkPointBack() {
    }


    @Around("dingTalkPointcut()")
    public Object dingTalkPointcut(ProceedingJoinPoint joinPoint) throws Throwable {
        // 执行发送方法

        return dingTalkService.executeSend(joinPoint);
    }


    @AfterReturning(
            pointcut = "dingTalkPointBack()",
            returning = "returnDto")
    public void logAfter(JoinPoint  joinPoint, Object returnDto) throws Exception {

        dingTalkService.executeSendBack(joinPoint, returnDto);
    }

}
